package com.k.ums.model;

import com.k.ums.util.CacheUtils;

import java.util.concurrent.TimeUnit;

/**
 * @Description:
 * @Author: kt
 * @CreateTime: 2022/2/19
 */
public class RemoveCacheTask implements Runnable {

    private String key;
    private long expireTime;

    public RemoveCacheTask(String key, long expireTime) {
        this.key = key;
        this.expireTime = expireTime;
    }

    @Override
    public void run() {
        long remaining = expireTime - System.currentTimeMillis();
        while (remaining > 0) {
            try {
                TimeUnit.MILLISECONDS.sleep(remaining);
            } catch (InterruptedException e) {
            }
            remaining = expireTime - System.currentTimeMillis();
        }
        // 删除缓存
        CacheUtils.delete(key);
    }
}